package DD6;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

public class CollectionTest {
	public static void main(String[] args) {
		CollectionTest ca = new CollectionTest();
		ca.test1();
		System.out.println();
		ca.test2();
		System.out.println();
		ca.test3();
		System.out.println();
		ca.test4();
	}

	public void test1() {

		Collection coll = new ArrayList();
		coll.add(123);
		coll.add(456);
		coll.add(new String("Tom"));
		coll.add(false);
		boolean contains = coll.contains(123);
		System.out.println(contains);
		System.out.println(coll.contains(new String("Tom")));
		Collection coll1 = Arrays.asList(123, 4567);
		System.out.println(coll.containsAll(coll1));
	}

	public void test2() {
		Collection coll = new ArrayList();
		coll.add(1234);
		coll.add(456);
		coll.add(123);
		
		coll.add(new String("Tom"));
		coll.add(false);
		System.out.println(coll);
		System.out.println(coll.remove(1234));
		System.out.println(coll);

		Collection coll1 = Arrays.asList(123, 456);
		coll.removeAll(coll1);
		System.out.println(coll);

	}

	public void test3() {
		Collection coll = new ArrayList();
		coll.add(123);
		coll.add(456);
		coll.add(new String("Tom"));
		coll.add(false);
		Collection coll1 = new ArrayList();
		coll1.add(456);
		coll1.add(123);
		//because Arraylists is ordered, so when we change the order of 123and 456, these two collection become different
		coll1.add(new String("Tom"));
		coll1.add(false);
		coll.retainAll(coll1);
		System.out.println(coll);
		System.out.println(coll.equals(coll1));

	}

	public void test4() {
		Collection coll = new ArrayList();
		coll.add(123);
		coll.add(456);
		coll.add(new String("Tom"));
		coll.add(false);

		System.out.println(coll.hashCode());

		Object[] arr = coll.toArray();
		for (int i = 0; i < arr.length; i++) {
			System.out.println(arr[i]);
		}

		List<String> list = Arrays.asList(new String[] { "AA", "BB", "CC" });
		System.out.println(list);

		List arr1 = Arrays.asList(new int[] { 123, 456 });
		System.out.println(arr1.size());// 1

		List arr2 = Arrays.asList(new Integer[] { 123, 456 });
		System.out.println(arr2.size());// 2

	}
}
